import sys


def solve():
    with open("words.txt", "r") as f:
        words = [line.strip() for line in f.readlines()]

    # 排序：首先按长度排序，长度相同则按字典序排序
    words.sort(key=lambda x: (len(x), x))

    # set存储所有优美字符串
    Bs = set()

    # 查找最长的优美字符串
    longestBs = ""

    for word in words:
        # 排序去掉末尾的字符串
        newsub = list(word[:-1])
        newsub.sort()
        # 排序整个字符串，为入库做准备
        news = list(word)
        news.sort()

        # 检查当前单词是否可以成为优美字符串
        if len(word) == 1 or str(newsub) in Bs:
            Bs.add(str(news))
            # 更新最长的优美字符串
            if len(word) > len(longestBs):
                longestBs = word
            # 一样长找字典序最小的
            elif len(word) == len(longestBs):
                longestBs = min(longestBs, word)

    return longestBs


sys.stdout.write(solve())
